/**
 * 2017年3月20日
 */
package cn.edu.bjtu.alex.rewrite.tools;

import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;

import cn.edu.bjtu.alex.rewrite.interfaces.Term;

/**
 * @author Alex
 *
 */
public abstract class AbstractFilter implements TermFilter{

	protected abstract boolean shouldRemove(Entry<String, Term> termEntry);
	@Override
	public final void filter(Map<String, Term> terms) {
		Iterator<Entry<String, Term>> iter = terms.entrySet().iterator();
		while(iter.hasNext()) {
			Entry<String, Term> entry = iter.next();
			if(entry.getValue().getWord() == null || shouldRemove(entry)) { 
				iter.remove();
			}
		}
		
	}

}
